﻿Module XML
    Public Sub AjoutePropXML(ByRef oXMLDoc As System.Xml.XmlDocument, ByRef oParent As System.Xml.XmlElement, ByVal Nom As String, ByVal Valeur As String)
        Dim oElement As System.Xml.XmlNode = oXMLDoc.CreateElement(Nom)
        oElement.InnerText = Valeur
        oParent.AppendChild(oElement)
    End Sub

    Public Function GetPropXMLDBL(ByRef oElement As System.Xml.XmlElement, ByVal Nom As String) As Double
        Dim sValue As String = GetPropXML(oElement, Nom)
        If IsNumeric(sValue) Then
            Return CDbl(sValue)
        Else
            Return (0.0)
        End If
    End Function

    Public Function GetPropXMLINT(ByRef oElement As System.Xml.XmlElement, ByVal Nom As String) As Integer
        Dim sValue As String = GetPropXML(oElement, Nom)
        If IsNumeric(sValue) Then
            Return CInt(sValue)
        Else
            Return (0)
        End If
    End Function

    Public Function GetPropXMLBool(ByRef oElement As System.Xml.XmlElement, ByVal Nom As String) As Boolean
        Dim sValue As String = GetPropXML(oElement, Nom)
        If sValue = Boolean.TrueString Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetPropXML(ByRef oElement As System.Xml.XmlElement, ByVal Nom As String) As String
        'Retourne la valeur du texte d'un noeud XML par nom à partir d'un document XML
        Dim oNodeList As System.Xml.XmlNodeList
        Dim oNode As System.Xml.XmlNode
        oNodeList = oElement.GetElementsByTagName(Nom)
        If oNodeList.Count > 0 Then
            'Récupérer le premier noeud
            oNode = oNodeList(0)
            'Obtenir le contenu
            Return Trim(oNode.InnerText)
        Else
            'On ne trouve pas ce noeud
            Return ""
        End If
    End Function
End Module
